Trò chơi 2D Cow Boy Runner

52.951 lượt xem;
1 using System.Collections;
2 using
System.Collections.Generic;
3 using
UnityEngine;
4
5 public
class GenerateForeGround : MonoBehaviour {
6
7     
public GameObject foregroundGenerator;
8     
public Transform generatePoint;
9
10     
private int groundSelect;
11     
public GameObject[] groundArray;
12
13     
private float minHeight;
14     
private float maxHeight;
15     
public Transform heightPoint;
16
17     
public float maxHeightChange;
18     
private float heightChange;
19
20     
public float distance;
21     
private float width;
22
23
24     
void Start () {
25
26         width = foregroundGenerator.GetComponent<BoxCollider2D> ().size.x;
27
28         minHeight = transform.position.y;
29         maxHeight = heightPoint.position.y;
30     }
31     
32
33     
void Update () {
34         
if(transform.position.x < generatePoint.position.x) {
35
36             transform.position =
new Vector3 (transform.position.x + distance, heightChange, transform.position.z);
37
38             groundSelect = Random.Range (
0, groundArray.Length);
39
40             Instantiate (groundArray[groundSelect], transform.position, transform.rotation);
41
42             heightChange = transform.position.y + Random.Range (maxHeightChange, -maxHeightChange);
43
44             
if(heightChange > maxHeight) {
45                 heightChange = maxHeight;
46
47             }
else if (heightChange < minHeight) {
48                 heightChange = minHeight;
49             }
50         }
51     }
52 }


Gõ tìm kiếm nhanh...